Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Count and Say (medium)
Problem Statement
Given an integer n greater than 0, return the nth count-and-say sequence.
A count-and-say sequence is a string of digits created using specific rules given below.
countAndSay(1) = "1"countAndSay(2) = say countAndSay(1)countAndSay(n) = say countAndSay(n - 1)
You start with "1", and for each subsequent string, you "read off" the digits of the previous string, counting the number of digits in groups of the same digit.
- For instance,
say "1223"is read off asone 1 + two 2 + one 3or112213.
Examples
-
Example 1:
- Input:
n = 3 - Expected Output:
"21" - Justification: The sequence is "1", "11" (one 1), "21" (two 1s).
- Input:
-
Example 2:
- Input:
n = 4 - Expected Output:
"1211" - Justification: Continuing from the last example, "21" is read as "one 2 + one 1" or "1211".
- Input:
-
Example 3:
- Input:
n = 5 - Expected Output:
"111221" - Justification: Continuing from the last example, "1211" is read as "one 1 + one 2 + two 1s" or "111221".
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Capacity To Ship Packages Within D Days
Solution: Count and Say
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself